import Vue from "vue";
import VueRouter from "vue-router";
// 导入路由页面组件
// import Home from "../views/Home"
// import Cart from "../views/Cart"
// import Category from "../views/Category"
// import Topic from "../views/Topic"
// import User from "../views/User"
// import searchPopup from "../views/searchPopup"
// import Banner from '../views/Banner'
// import About from '../views/About'
import { Dialog } from "vant";
// import Ress from '../views/Ress'
Vue.use(VueRouter)
// 模块路由配置
const router = new VueRouter({
    routes: [
        //重定向
        {
            path: "/",
            redirect: "/home",
        },
        // 首页
        {
            path: "/home",
            name: "Home",
            component: ()=>import("../views/Home"),
            // meta:{// ********************
            //     isShowTabbar: true,
            // },
            children: [
                {
                    path: "searchPopup",
                    name: "searchPopup",
                    component:()=>import("../views/searchPopup"),
                },
                // 轮播图下面导航
                {
                    path: "banner",
                    name: "banner",
                    component:()=>import('../views/Banner'),
                },

            ],

        },
        // 专题
        {
            path: "/topic",
            name: "Topic",
            component: ()=>import("../views/Topic"),
            meta: {// ********************
                isShowTabbar: true,
            }
        },
        // 分类
        {
            path: "/category",
            name: "Category",
            component:()=>import("../views/Category"),
            meta: {// ********************
                isShowTabbar: true,
            }
        },
        // 购物车
        {
            path: "/cart",
            name: "Cart",
            component: ()=>import("../views/Cart"),
            // meta: {// ********************
            //     isShowTabbar: true,
            // }

        },
        // 我的
        {
            path: "/user",
            name: "User",
            component:()=>import("../views/User"),
            meta: {// ********************
                isShowTabbar: true,
            },
            children:[
                {
                    path:"ress",
                    name:"Ress",
                    component:()=>import('../views/Ress'),
                }
            ]
        },
        {
            path: "/about",
            name: "About",
            component:()=>import('../views/About'),
            // meta: {// ********************
            //     isShowTabbar: true,
            // },
        },
    ],
    mode: "history",
})
router.beforeEach((to, from, next) => {
    if (to.path == "/cart" && !localStorage.getItem("token")) {
        Dialog.alert({
            message: "请先登录",
        });
        next("/user")
    } else {
        next()
    }
})

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err);
};

// 暴露出去
export default router